package com.kantboot.system.user.web.admin.controller;

import com.kantboot.system.user.domain.dto.SysRoleSearchDTO;
import com.kantboot.system.user.domain.entity.SysRole;
import com.kantboot.system.user.service.ISysRoleService;
import com.kantboot.util.common.result.RestResult;
import com.kantboot.util.core.controller.BaseAdminController;
import com.kantboot.util.core.param.PageParam;
import com.kantboot.util.core.result.PageResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system-user-web/admin/role")
public class SysRoleControllerOfAdminController
extends BaseAdminController<SysRole,Long>
{

    @Resource
    private ISysRoleService service;

    @RequestMapping("/getBodyData")
    public RestResult<PageResult> getBodyData(@RequestBody PageParam<SysRoleSearchDTO> pageParam) {
        return RestResult.success(service.getBodyData(pageParam),"getSuccess","获取成功");
    }

    /**
     * 根据角色code获取权限code列表
     */
    @RequestMapping("/getPermissionCodeListByRoleCode")
    public RestResult<Iterable<String>> getPermissionCodeListByRoleCode(@RequestParam("roleCode") String roleCode) {
        return RestResult.success(service.getPermissionCodeListByRoleCode(roleCode),"getSuccess","获取成功");
    }

    /**
     * 绑定角色权限
     */
    @RequestMapping("/bindPermission")
    public RestResult<Void> bindPermission(@RequestParam("roleCode") String roleCode, @RequestParam("permissionCodeList") List<String> permissionCodeList) {
        service.bindPermission(roleCode,permissionCodeList);
        return RestResult.success(null,"bindSuccess","绑定成功");
    }

}
